<?php
namespace Common\Model;

use Common\Model\CommonModel;

class UsersModel extends CommonModel
{

    protected $_validate = array(
        //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
        array('name', 'require', '用户名称不能为空！', 1, 'regex', CommonModel:: MODEL_INSERT),


    );


    protected $_auto = array(

        array('create_time', 'time', 1, 'function'), // 对password字段在新增和编辑的时候使md5函数处理

    );


    public function chongzhi($uid, $money)
    {

//        $song = D("Zengsong")->get_song($money);
//
//        $price = $money + $song;
//
//
//
//        $yue=D("Users")->where(array("id"=>$uid))->getField("money");
//        D("Users")->where(array("id"=>$uid))->save(array("money"=>$money+$yue));


        if($money<0){
            return false;
        }


        D("Users")->where(array("id"=>$uid))->setInc("money",$money);


        $s=D("Users")->where(array("id"=>$uid))->getField("money");


        return $s;


    }




    public  function  fanxian($order_sn,$bili){






        $order=M("Order")->where(array("order_sn"=>$order_sn))->find();




        $y_user=D("Users")->where(array("id"=>$order["uid"]))->find();






        $jid=$y_user["j_id"];


        if(!$jid){
            return false;
        }




            $fan_money=$order['price_sum']*$bili;

            $ymoney=D("Users")->where(array("id"=>$jid))->getField("jiangjin");
            $new_money=$ymoney+$fan_money;

            D("Users")->where(array("id"=>$jid))->save(array("jiangjin"=>$new_money));

            $data=array(
                "uid"=>$jid,
                "money"=>$fan_money,
                "time"=>time(),
                "order_sn"=>$order_sn,
                "yue"=>$new_money,
                "type"=>"奖金",
            );


            M("JjLog")->add($data);










    }

    public function xiaofei($uid, $money)
    {



        $yue=D("Users")->where(array("id"=>$uid))->getField("money");


        if($yue<$money){

            return false;
        }
        else{
            D("Users")->where(array("id"=>$uid))->save(array("money"=>$yue-$money));
            return true;
        }



    }

    public function get_info_id($where){


        $info=$this->where($where)->find();



        if($info){

            $info["zu"]=M("Group")->find($info["group"]);
            return  $info;

        }else{


            return false;
        }









    }


}

?>